import store from '@/store/index.js'
export default{
  beforeRouteLeave(to,from,next){
    console.log(`leave`);
    store.saveRoutePosition(from,document.documentElement.scrollTop);
    next();
  },
  beforeRouteEnter(to,from,next){
    next(vm => {
      let position = store.getRoutePosition(to);
      console.log(`enter`);
      if(to.meta.keepAlive){
        document.documentElement.scrollTop = position;
      }else{
        //这里有浏览器自己的定位，主动点击有效，浏览器返回无效
        console.log('enter',to,from);
        if(from.name){
          //没有name说明是从别的页面过来的
          document.documentElement.scrollTop = 0;
        }
      }
    });
  }
}
